/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package arbitration.gui;

import com.toedter.calendar.JCalendar;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author prophet
 */
public class SettingsPanel extends JPanel implements ActionListener{    
    private JCalendar calendar;
    private JButton addHoliday;
    private JButton removeHoliday;
    private DefaultTableModel percentDtm;
    private JTable percentTable;
    private DefaultTableModel rateDtm;
    private JTable rateTable;

    public SettingsPanel(){
        this.setLayout(new BorderLayout());

        JPanel settings=new JPanel();
        settings.setLayout(new GridBagLayout());
        int y=0;        
        calendar=new JCalendar();
        calendar.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        settings.add(calendar, new GridBagConstraints(0, 0, 5, 5, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(30, 10, 10, 10), 0, 0));
        addHoliday=new JButton("сделать нерабочим");
        addHoliday.setName("Holiday");
        addHoliday.addActionListener(this);
        addHoliday.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        settings.add(addHoliday, new GridBagConstraints(6, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(30, 10, 0, 10), 0, 0));
        removeHoliday=new JButton("сделать рабочим");
        removeHoliday.setName("Weekday");
        removeHoliday.addActionListener(this);
        removeHoliday.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        settings.add(removeHoliday, new GridBagConstraints(6, 1, 1, 1, 0, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(5, 10, 10, 10), 0, 0));

        percentDtm = new DefaultTableModel();
        percentDtm.addColumn("Цена иска");
        percentDtm.addColumn("Размер арбитражного сбора");
        
        percentDtm.addRow(new String[]{"До 1000 базовых величин","3"+" процента от цены  иска"});
        percentDtm.addRow(new String[]{"От 1000 до 10000 базовых величин","2"+" процента от цены  иска"});
        percentDtm.addRow(new String[]{"Свыше 10000 базовых величин","1"+" процент от цены  иска"});
        percentTable = new JTable(percentDtm){
            @Override
            public boolean isCellEditable ( int row, int column )
            {
                return false;
            }
        };
        percentTable.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        percentTable.getTableHeader().setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        percentTable.setShowHorizontalLines(false);
        percentTable.setSelectionBackground(Color.black);
        percentTable.setSelectionForeground(Color.white);
        percentTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        
        JScrollPane p=new JScrollPane(percentTable);
        p.setPreferredSize(new Dimension(100, 150));
        settings.add(p, new GridBagConstraints(7, 0, 5, 5, 1, 0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(30, 30, 10, 10), 0, 0));

        rateDtm = new DefaultTableModel();
        rateDtm.addColumn("Цена иска");
        rateDtm.addColumn("Размер арбитражного сбора");
        
        rateDtm.addRow(new String[]{"До 1000 базовых величин","3"+" процента от цены  иска"});
        rateDtm.addRow(new String[]{"От 1000 до 10000 базовых величин","2"+" процента от цены  иска"});
        rateDtm.addRow(new String[]{"Свыше 10000 базовых величин","1"+" процент от цены  иска"});
        rateTable = new JTable(percentDtm){
            @Override
            public boolean isCellEditable ( int row, int column )
            {
                return false;
            }
        };
        rateTable.setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        rateTable.getTableHeader().setFont(new Font("Tahoma", Font.TRUETYPE_FONT, 11));
        rateTable.setShowHorizontalLines(false);
        rateTable.setSelectionBackground(Color.black);
        rateTable.setSelectionForeground(Color.white);
        rateTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        
               
        //settings.add(new JScrollPane(rateTable), new GridBagConstraints(0, 6, 12, 1, 1, 1, GridBagConstraints.NORTH,
          //  GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));

        add(settings,BorderLayout.NORTH);
        add(new JScrollPane(rateTable),BorderLayout.CENTER);
    }

    public void actionPerformed(ActionEvent e) {
        Object ob = e.getSource();
        if (((Component) ob).getName().equals("Holiday")) {
            if(!calendar.getHolidayPolicy().isHoliday(calendar.getCalendar())){
                if(calendar.getHolidayPolicy().isWeekend(calendar.getCalendar())){
                    calendar.getDayChooser().removeWeekday(calendar.getCalendar());
                }else{
                    calendar.getDayChooser().addHoliday(calendar.getCalendar());
                }
            }
        }

        if (((Component) ob).getName().equals("Weekday")) {
            if(calendar.getHolidayPolicy().isHoliday(calendar.getCalendar())){
               if(calendar.getHolidayPolicy().isWeekend(calendar.getCalendar())) {
                   calendar.getDayChooser().addWeekday(calendar.getCalendar());
               }else{
                   calendar.getDayChooser().removeHoliday(calendar.getCalendar());
               }
            }
        }
    }

    public JCalendar getCalendar() {
        return calendar;
    }

    public void setCalendar(JCalendar calendar) {
        this.calendar = calendar;
    }

    
}
